﻿BEGIN TRANSACTION
GO

/* 
	Table: [plexbb_GlobalSetting]
*/
CREATE TABLE [plexbb_GlobalSetting](
	[Name] [varchar](50) NOT NULL,
	[Value] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_plexbb_GlobalSetting] PRIMARY KEY CLUSTERED 
(
	[Name] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

/* 
	Table: [plexbb_Module]
*/
CREATE TABLE [plexbb_Module](
	[ModuleID] [int] IDENTITY(1,1) NOT NULL,
	[ModuleType] [char](3) NOT NULL,
	[ParentID] [int] NULL,
	[ControlType] [varchar](255) NULL,
	[ModuleMode] [varchar](255) NULL,
	[LangName] [varchar](255) NOT NULL,
	[Position] [int] NOT NULL,
	[Enabled] [bit] NOT NULL,
	[Display] [bit] NOT NULL,
 CONSTRAINT [PK_plexbb_Module] PRIMARY KEY CLUSTERED 
(
	[ModuleID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [plexbb_Module]  WITH CHECK ADD  CONSTRAINT [Module_Module] FOREIGN KEY([ParentID])
REFERENCES [plexbb_Module] ([ModuleID])
GO

/* 
	Table: [plexbb_User]
*/
CREATE TABLE [dbo].[plexbb_User](
	[UserID] [int] IDENTITY(1,1) NOT NULL,
	[UserType] [int] NOT NULL,
	[Password] [binary](48) NULL,
	[PasswordSalt] [binary](48) NULL,
	[UserName] [nvarchar](255) NOT NULL,
	[LastVisit] [datetime] NULL,
	[RegisteredDate] [datetime] NOT NULL,
	[RegisteredIP] [varchar](40) NOT NULL,
	[Posts] [int] NOT NULL,
	[Warnings] [int] NOT NULL,
	[Email] [varchar](100) NOT NULL,
 CONSTRAINT [PK_plexbb_User] PRIMARY KEY CLUSTERED 
(
	[UserID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[plexbb_User] ADD  CONSTRAINT [DF_plexbb_User_RegisteredDate]  DEFAULT (getdate()) FOR [RegisteredDate]
GO

ALTER TABLE [dbo].[plexbb_User] ADD  CONSTRAINT [DF_plexbb_User_Posts]  DEFAULT ((0)) FOR [Posts]
GO

ALTER TABLE [dbo].[plexbb_User] ADD  CONSTRAINT [DF_plexbb_User_Warnings]  DEFAULT ((0)) FOR [Warnings]
GO

ALTER TABLE [dbo].[plexbb_User] ADD  CONSTRAINT [DF_plexbb_User_UserType]  DEFAULT ((0)) FOR [UserType]
GO

ALTER TABLE [dbo].[plexbb_User] ADD  CONSTRAINT [DF_plexbb_User_Email]  DEFAULT ('') FOR [Email]
GO

/* 
	Table: [plexbb_ForumSession]
*/
CREATE TABLE [plexbb_ForumSession](
	[SessionID] [char](32) NOT NULL,
	[UserID] [int] NULL,
	[IP] [varchar](40) NOT NULL,
 CONSTRAINT [PK_plexbb_ForumSession] PRIMARY KEY CLUSTERED 
(
	[SessionID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [plexbb_ForumSession]  WITH CHECK ADD  CONSTRAINT [ForumSession_User] FOREIGN KEY([UserID])
REFERENCES [plexbb_User] ([UserID])
ON DELETE SET NULL
GO

ALTER TABLE [plexbb_ForumSession] CHECK CONSTRAINT [ForumSession_User]
GO

/* 
	Table: [plexbb_Forum]
*/
CREATE TABLE plexbb_Forum(
	ForumID int IDENTITY(1,1) NOT NULL,
	ParentID int,
	Position int NOT NULL,
	Name nvarchar(1000) NOT NULL,
	Description nvarchar(2000) NOT NULL,
	Password binary(48) NULL,
	PasswordSalt binary(48) NULL,
	Link nvarchar(255) NOT NULL,
	ImageUrl nvarchar(255) NOT NULL,
	ForumType int NOT NULL,
	Status int NOT NULL,
	CONSTRAINT PK_plexbb_Forum PRIMARY KEY (ForumID)
)
GO

ALTER TABLE plexbb_Forum ADD CONSTRAINT FK_plexbb_Forum_plexbb_Forum FOREIGN KEY (ParentID)
REFERENCES plexbb_Forum (ForumID)
GO


/* 
	User: Anonymous
*/
INSERT INTO [dbo].[plexbb_User] ([UserName], [UserType], [RegisteredIP]) VALUES ('Anonymous', 2, '127.0.0.1')
GO

COMMIT
GO